package analyzer;

import java.util.Arrays;

public class Common {
    public static byte[] magic = {(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00};
    static byte[] magic_be = {(byte) 0xa1, (byte) 0xb2, (byte) 0xc3, (byte) 0xd4};
    static byte[] magic_le = {(byte) 0xd4, (byte) 0xc3, (byte) 0xb2, (byte) 0xa1};
    public static int convertToInt(byte[] bytes)
    {
        int num = 0;
        if (Arrays.equals(Common.magic,magic_le))
        {
            num += bytes[0]&0xff;
            num += 256 * (bytes[1]&0xff);
            num += 256 * 256 * (bytes[2]&0xff);
            num +=256 * 256 * 256 * (bytes[3]&0xff);
        }
        else if (Arrays.equals(Common.magic,magic_be))
        {
            num += bytes[3]&0xff;
            num += 256 * (bytes[2]&0xff);
            num += 256 * 256 * (bytes[1]&0xff);
            num +=256 * 256 * 256 * (bytes[0]&0xff);
        }
        return num;
    }
}
